package per.zhou.testffmpeg;

import android.os.Bundle;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @author zkingcobra
 */
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback {

    // Used to load the 'native-lib' library on application startup.

    EnjoyPlayer enjoyPlayer;

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = findViewById(R.id.sample_text);

        SurfaceView surfaceView = findViewById(R.id.testSurfaceView);

        surfaceView.getHolder().addCallback(this);

        enjoyPlayer = new EnjoyPlayer();
        //enjoyPlayer.setDataSource(
        //        "/sdcard/[Skytree][东京食尸鬼][Tokyo_Ghoul][01][GB_JP][X264_AAC][720P高码][HDTVRIP][天空树双语字幕组]V2.mp4");
        enjoyPlayer.setDataSource("http://al.hls.huya.com/backsrc/44992571-44992571-193241621007958016-25445436-10057-A-0-1.m3u8");

        enjoyPlayer.setOnPrepareListener(new EnjoyPlayer.OnPrepareListener() {
            @Override public void onPrepared() {
                enjoyPlayer.start();
            }
        });
        enjoyPlayer.prepare();

        //tv.setText(" " +  stringFFmpegVersion() );
    }

    @Override public void surfaceCreated(SurfaceHolder holder) {

    }

    @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        Surface surface = holder.getSurface();
        enjoyPlayer.setSurface(surface);
    }

    @Override public void surfaceDestroyed(SurfaceHolder holder) {

    }

    ///**
    // * A native method that is implemented by the 'native-lib' native library,
    // * which is packaged with this application.
    // */
    //public native String stringFFmpegVersion();
    //
    //public native int getFFmpegVersion();
}
